#include "inputkey.h"

int cptkey = 0;

void OnKeyPressed(int key) {
	if(key > 0){
		char keypressed[1];
		sprintf(keypressed,"%c", key);
		NF_WriteText(0, 0, 5 + cptkey, 2 , keypressed);
		NF_UpdateTextLayers();
		cptkey++;
	}
}


char * inputkey(const char* message){
	cptkey = 0;
	NF_WriteText(0, 0, 5, 2 , "               ");
	//Keyboard *kbd = 	keyboardDemoInit();
	Keyboard *kbd = keyboardInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 20, 0, false, true);
	kbd->OnKeyPressed = OnKeyPressed;
	/*scanf("%s", login);
	return login;*/
	
	char myName[64];
	
	NF_WriteText(0, 0, 5, 1 , message);
	NF_UpdateTextLayers();
	scanf("%s", myName);

	//NF_WriteText(0, 0, 5, 2 , myName);

	/*scanKeys();
	while(!keysDown())scanKeys();*/

	//NF_WriteText(0, 0, 5, 4 , myName);
	
	char * ret = (char*) malloc(strlen(myName) * sizeof(char));
	strcpy(ret,myName);
	
	//NF_WriteText(0, 0, 5, 5 , ret);
	swiWaitForVBlank();
	consoleClear();
	
	return ret;
}